You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
811 B
20 lines
811 B
import { updateArticle } from "#server/service/article";
|
|
import { getContextUser } from "#server/utils/context";
|
|
import { z } from "zod";
|
|
|
|
export default defineWrappedResponseHandler({ auth: "required" }, async (event) => {
|
|
const user = getContextUser(event)!;
|
|
const id = parseInt(event.context.params!.id);
|
|
const body = await readBody(event);
|
|
const parsed = z.object({
|
|
title: z.string().optional(),
|
|
content: z.string().optional(),
|
|
status: z.enum(["draft", "published"]).optional(),
|
|
coverUrl: z.string().optional().nullable(),
|
|
}).safeParse(body);
|
|
if (!parsed.success) return R.error("参数校验失败", parsed.error.issues);
|
|
|
|
const article = await updateArticle(id, user.id, parsed.data);
|
|
if (!article) return R.error("文章不存在", null);
|
|
return R.success(article);
|
|
});
|
|
|